package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.example.config.RocketMQConfigProperties;
import org.example.utils.TmpTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/delay")
public class DelayController {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Autowired
    private RocketMQConfigProperties prop;

    @RequestMapping("/send")
    public String send() {
        rocketMQTemplate.syncSend(prop.getTopic().get("delay"),
                new GenericMessage<>("我是延迟消息" + TmpTools.timeToString(new Date().getTime())),
                3000,
                3);
        return "ok";
    }
}
